var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');

var lagouMockMiddleware = require('../lagou-mock-middleware');

var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');

var app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'html');
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({extended: false}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/users', usersRouter);
app.use('*', lagouMockMiddleware({
    mockServerConfig: {
        '/user/info': '/a.html',
        '/user/info2': 'info.json',
        '/user/info3': {
            'name': 'jingyang'
        },
        '/user/info4': {
            'GET': function (query, body) {
                return 'hello word';
            }
        },
    },
    mockJsonDir: path.join(__dirname, './mockDir')
}));

module.exports = app;
